#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

const int N = 1e4 + 10;
int sum[N];
int f[N], g[N];
int n;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        sum[x] += x;
    }

    f[0] = g[0] = 0;

    for (int i = 1; i < N;i++)
    {
        f[i] = sum[i] + g[i - 1];
        g[i] = max(f[i - 1], g[i - 1]);
    }

    cout << max(f[N - 1], g[N - 1]) << endl;

    return 0;
}